/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package daw.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Christian
 */
@Entity
@Table(name = "delito_subdelito")
@NamedQueries({@NamedQuery(name = "DelitoSubdelito.findAll", query = "SELECT d FROM DelitoSubdelito d"),
@NamedQuery(name = "DelitoSubdelito.findByIdDelito", query = "SELECT d FROM DelitoSubdelito d WHERE d.delitoSubdelitoPK.idDelito = :idDelito"),
@NamedQuery(name = "DelitoSubdelito.findByIdSubDelito", query = "SELECT d FROM DelitoSubdelito d WHERE d.delitoSubdelitoPK.idSubDelito = :idSubDelito")})
public class DelitoSubdelito implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DelitoSubdelitoPK delitoSubdelitoPK;
    @JoinColumn(name = "idDelito", referencedColumnName = "idDelito", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Delito delito;
    @JoinColumn(name = "idSubDelito", referencedColumnName = "idSubDelito", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Subdelito subdelito;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "delitoSubdelito")
    private List<Denuncia> denunciaCollection;

    public DelitoSubdelito() {
    }

    public DelitoSubdelito(DelitoSubdelitoPK delitoSubdelitoPK) {
        this.delitoSubdelitoPK = delitoSubdelitoPK;
    }

    public DelitoSubdelito(int idDelito, int idSubDelito) {
        this.delitoSubdelitoPK = new DelitoSubdelitoPK(idDelito, idSubDelito);
    }

    public DelitoSubdelitoPK getDelitoSubdelitoPK() {
        return delitoSubdelitoPK;
    }

    public void setDelitoSubdelitoPK(DelitoSubdelitoPK delitoSubdelitoPK) {
        this.delitoSubdelitoPK = delitoSubdelitoPK;
    }

    public Delito getDelito() {
        return delito;
    }

    public void setDelito(Delito delito) {
        this.delito = delito;
    }

    public Subdelito getSubdelito() {
        return subdelito;
    }

    public void setSubdelito(Subdelito subdelito) {
        this.subdelito = subdelito;
    }

    public List<Denuncia> getDenunciaCollection() {
        return denunciaCollection;
    }

    public void setDenunciaCollection(List<Denuncia> denunciaCollection) {
        this.denunciaCollection = denunciaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (delitoSubdelitoPK != null ? delitoSubdelitoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof DelitoSubdelito)) {
            return false;
        }
        DelitoSubdelito other = (DelitoSubdelito) object;
        if ((this.delitoSubdelitoPK == null && other.delitoSubdelitoPK != null) || (this.delitoSubdelitoPK != null && !this.delitoSubdelitoPK.equals(other.delitoSubdelitoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "daw.bean.DelitoSubdelito[delitoSubdelitoPK=" + delitoSubdelitoPK + "]";
    }

    public static List<Delito> DelitoSubdelitoCollectionToDelitoCollection(List<DelitoSubdelito> delitossubdelitos){
        ArrayList delitos = new ArrayList();
        Iterator i = delitossubdelitos.iterator();
        while(i.hasNext()){
            Delito c = ((DelitoSubdelito)i.next()).getDelito();
            delitos.add(c);
        }
        return delitos;
    }

    public static List<Subdelito> DelitoSubdelitoCollectionToSubDelitoCollection(List<DelitoSubdelito> delitossubdelitos){
        ArrayList subdelitos = new ArrayList();
        Iterator i = delitossubdelitos.iterator();
        while(i.hasNext()){
            Subdelito c = ((DelitoSubdelito)i.next()).getSubdelito();
            subdelitos.add(c);
        }
        return subdelitos;
    }
}
